<?php
/**
 * author: yunshu
 * createTime: 18/2/23 18:42
 * description:
 */

namespace app\common\model;


use app\common\service\TokenService;

class Order extends Base
{
    protected $hidden = ['id', 'user_id', 'create_time', 'update_time', 'delete_time', 'prepay_id'];
    protected $autoWriteTimestamp = true;

    public static function instance($class = __CLASS__)
    {
        return parent::instance($class);
    }

    public function getSummary($page, $size)
    {
        //使用简洁分页: 仅仅只有上下页的分页输出
        return self::order('create_time desc')->paginate($size, true, ['page'=>$page])->hidden(['snap_items', 'snap_address'])->toArray();
    }

    public function getSummaryByUser($uid, $page, $size)
    {
        return self::where('user_id', '=', $uid)->order('create_time desc')->paginate($size, true, ['page'=>$page])->hidden(['snap_items', 'snap_address'])->toArray();

    }

    public function getSnapItemsAttr($value)
    {
        if (! $value) {
            return null;
        }

        return json_decode($value);
    }

    public function getSnapAddressAttr($value)
    {
        if (! $value) {
            return null;
        }

        return json_decode($value);
    }
}